package cn.wolfcode.restful.controller;

import cn.wolfcode.restful.domain.Employee;
import cn.wolfcode.restful.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;


@RequestMapping("/employees")
public class EmployeeController_bak {
    //增
    @RequestMapping(value = "/employees",method = RequestMethod.POST)
    @ResponseBody
    public Employee save(Employee employee){
        /*employee.setId(3);
        employee.setName("张三");
        employee.setAge(18);*/
        return employee;
    }
    //删
    @RequestMapping(value = "/employees/{id}",method = RequestMethod.DELETE)
    @ResponseBody
    public JsonResult delete(@PathVariable int id){
        return JsonResult.success(id);
    }
    //改
    @RequestMapping(value = "/employees",method = RequestMethod.PUT)
    @ResponseBody
    public Employee update(Employee employee){

        return employee;
    }
    //查所有
    @RequestMapping(value = "/employees",method = RequestMethod.GET)
    @ResponseBody
    public List<Employee> queryAll(){
        return  Arrays.asList(new Employee(1,"zz",8),new Employee(2,"hh",50));
    }
    //查单个
    @RequestMapping(value = "/employees/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Employee queryOne(@PathVariable int id){
        return new Employee(id,"zz",8);
    }
}
